package com.wlcorp.forcazamis.business.stock.impl;

import java.util.List;

import com.wlcorp.forcazamis.business.stock.IStockService;
import com.wlcorp.forcazamis.dao.stock.IStockDAO;
import com.wlcorp.forcazamis.dao.stock.IStockFittingDAO;
import com.wlcorp.forcazamis.dao.stock.IStockProductDAO;
import com.wlcorp.forcazamis.dao.stock.IStockProductDetailDAO;
import com.wlcorp.forcazamis.domain.stock.Stock;
import com.wlcorp.forcazamis.domain.stock.StockFitting;
import com.wlcorp.forcazamis.domain.stock.StockProduct;
import com.wlcorp.forcazamis.domain.stock.StockProductDetail;
import com.wlcorp.forcazamis.exception.ServiceException;
import com.wlcorp.forcazamis.sys.BaseService;
import com.wlcorp.forcazamis.sys.util.AppConstant;

public class StockServiceImpl extends BaseService implements IStockService {

	public void deleteStock(Stock stock) throws ServiceException {
		stockDAO.deleteStock(stock);
	}

	public void deleteStockFitting(StockFitting stockFitting)
			throws ServiceException {
		stockFittingDAO.deleteStockFitting(stockFitting);
	}

	public void deleteStockProduct(StockProduct stockProduct)
			throws ServiceException {
		stockProductDAO.deleteStockProduct(stockProduct);
	}

	public Stock getStockById(Long stockId) throws ServiceException {
		if (null == stockId) {
			return null;
		}
		return stockDAO.getStockById(stockId);
	}

	public StockFitting getStockFittingById(Long stockFittingId)
			throws ServiceException {
		if (null == stockFittingId) {
			return null;
		}
		return stockFittingDAO.getStockFittingById(stockFittingId);
	}

	public StockProduct getStockProductById(Long stockProductId)
			throws ServiceException {
		if (null == stockProductId) {
			return null;
		}
		return stockProductDAO.getStockProductById(stockProductId);
	}

	public List<StockFitting> getStockFittingList(StockFitting stockFitting)
			throws ServiceException {
		return stockFittingDAO.getStockFittingList(stockFitting);
	}

	public List<Stock> getStockList(Stock stock) throws ServiceException {
		return stockDAO.getStockList(stock);
	}

	public List<StockProduct> getStockProductList(StockProduct stockProduct)
			throws ServiceException {
		return stockProductDAO.getStockProductList(stockProduct);
	}

	public void saveStock(Stock stock) throws ServiceException {
		stockDAO.saveStock(stock);
	}
	
	public void updateStock(Stock stock) throws ServiceException {
		stockDAO.updateStock(stock);
	}

	public void saveStockFitting(StockFitting stockFitting)
			throws ServiceException {
		stockFittingDAO.saveStockFitting(stockFitting);
	}

	public void saveStockProduct(StockProduct stockProduct)
			throws ServiceException {
		stockProductDAO.saveStockProduct(stockProduct);
	}

	public void updateStockProduct(StockProduct stockProduct)
			throws ServiceException {
		stockProductDAO.updateStockProduct(stockProduct);
	}

	public Long getMaxStockProductId() throws ServiceException {
		return stockProductDAO.getMaxStockProductId();
	}

	public List<StockProduct> getStockProductListByStockId(Long stockId)
			throws ServiceException {
		return stockProductDAO.getStockProductListByStockId(stockId);
	}

	public void deleteStockProductDetail(StockProductDetail stockProductDetail)
			throws ServiceException {
		stockProductDetailDAO.deleteStockProductDetail(stockProductDetail);
	}

	public StockProductDetail getStockProductDetailById(
			Long stockProductDetailId) throws ServiceException {
		return stockProductDetailDAO
				.getStockProductDetailById(stockProductDetailId);
	}

	public List<StockProductDetail> getStockProductDetailList(
			StockProductDetail stockProductDetail) throws ServiceException {
		return stockProductDetailDAO
				.getStockProductDetailList(stockProductDetail);
	}

	public void saveStockProductDetail(StockProductDetail stockProductDetail)
			throws ServiceException {
		stockProductDetailDAO.saveStockProductDetail(stockProductDetail);
	}

	public void drawbackStock(Stock stock) throws ServiceException {
		stock.setState(AppConstant.BILL_STATE_SUBMITED);
		stockDAO.saveStock(stock);
	}
	
	private IStockDAO stockDAO;
	private IStockFittingDAO stockFittingDAO;
	private IStockProductDAO stockProductDAO;
	private IStockProductDetailDAO stockProductDetailDAO;

	public IStockDAO getStockDAO() {
		return stockDAO;
	}

	public void setStockDAO(IStockDAO stockDAO) {
		this.stockDAO = stockDAO;
	}

	public IStockFittingDAO getStockFittingDAO() {
		return stockFittingDAO;
	}

	public void setStockFittingDAO(IStockFittingDAO stockFittingDAO) {
		this.stockFittingDAO = stockFittingDAO;
	}

	public IStockProductDAO getStockProductDAO() {
		return stockProductDAO;
	}

	public void setStockProductDAO(IStockProductDAO stockProductDAO) {
		this.stockProductDAO = stockProductDAO;
	}

	public Stock getStockByStockCodeAndFactoryId(String stockCode,
			Long factoryId) throws ServiceException {
		return stockDAO.getStockByStockCodeAndFactoryId(stockCode, factoryId);
	}

	public Long getMaxStockId() throws ServiceException {
		return stockDAO.getMaxStockId();
	}

	public Long getStockCount(Stock stock) throws ServiceException {
		return stockDAO.getStockCount(stock);
	}

	public IStockProductDetailDAO getStockProductDetailDAO() {
		return stockProductDetailDAO;
	}

	public void setStockProductDetailDAO(
			IStockProductDetailDAO stockProductDetailDAO) {
		this.stockProductDetailDAO = stockProductDetailDAO;
	}

	public List<StockProductDetail> getListByCondition(StockProductDetail stockProductDetail)
			throws ServiceException {
		return stockProductDetailDAO.getListByCondition(stockProductDetail);
	}

	public Long getStockProductDetailCount(StockProductDetail stockProductDetail)
			throws ServiceException {
		return stockProductDetailDAO.getStockProductDetailCount(stockProductDetail);
	}
}
